package cn.iocoder.yudao.framework.common.genCode.xk.info;

import lombok.Builder;
import lombok.Data;
import org.springframework.util.StringUtils;

@Data
@Builder
/**
 * 要先set 组件名 和 插件名
 * build() 之后要 calc()
 * 有7个类
 */
public class ClassInfo {

    public static final String FIXED_PREFIX = "com.oneheart.xp.plugin.";
    public static final String CARD_SUFFIX = "CardService";
    public static final String LIST_SUFFIX = "ListService";
    public static final String ENTITY_SUFFIX = "Entity";
    public static final String ENTITY_BUF_SUFFIX = "EntityBuffer";
    public static final String COMBO_SUFFIX = "ComboService";
    public static final String DAO_SUFFIX = "Dao";
    public static final String DIALOG_SUFFIX = "DialogService";


    /**
     * 组件名首字母大写 = 类名共同前缀
     */
    private String clsNamePre;

    /**
     * 插件名
     */
    private String pluginName;

    /**
     * 组件名
     */
    private String componentName;

    /**
     * 包名
     */
    private String packageName;

    /**
     * cardService 类名
     */
    private String cardClassName;

    /**
     * comboService 类名
     */
    private String comboClassName;

    /**
     * daoService 类名
     */
    private String daoClassName;


    /**
     * entity 类名
     */
    private String entityClassName;

    /**
     * entityBuffer 类名
     */
    private String entityBufferClassName;

    /**
     * listService 类名
     */
    private String listClassName;

    /**
     * DialogService 类名
     */
    private String dialogClassName;


    public ClassInfo calc() throws Exception {
        if (!StringUtils.hasLength(getPluginName())) throw new Exception("插件名不能为空！");
        if (!StringUtils.hasLength(getComponentName())) throw new Exception("组件名不能为空！");
        setPackageName(FIXED_PREFIX + getPluginName());
        setClsNamePre(StringUtils.capitalize(getComponentName()));
        setEntityClassName(getClsNamePre() + ENTITY_SUFFIX);
        setEntityBufferClassName(getClsNamePre() + ENTITY_BUF_SUFFIX);
        setCardClassName(getClsNamePre() + CARD_SUFFIX);
        setListClassName(getClsNamePre() + LIST_SUFFIX);
        setComponentName(getClsNamePre() + CARD_SUFFIX);
        setComboClassName(getClsNamePre() + CARD_SUFFIX);
        setDialogClassName(getClsNamePre() + DIALOG_SUFFIX);
        return this;
    }


}
